<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet"  href="/layui/css/layui.css"/>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>用户列表</title>
</head>
<body>
<script src="/plugins/jquery/jquery-1.10.2.min.js"></script>
<script  src="/layui/layui.js"></script>
<script src="/plugins/js/common.js"></script>
<script src="/plugins/js/md5.js"></script>
<form class="layui-form" action="/user/updateUserPassword" id="updateForm">
	<br>
	<div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">原密码：</label>
	      <div class="layui-input-inline">
	        <input type="password" name="oldPassword" id="oldPassword" placeholder="请输入原密码" lay-verify="required|validateOldPassword" autocomplete="off" style="width: 260px;" class="layui-input">
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">新密码：</label>
	      <div class="layui-input-inline">
	        <input type="password" name="password" id="password" placeholder="请输入新密码" lay-verify="required" style="width: 260px;" autocomplete="off" class="layui-input">
	      </div>
	    </div>
  </div>
   <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">确认密码：</label>
	      <div class="layui-input-inline">
	        <input type="password" id="confirmPassword" name="confirmPassword" placeholder="请输入确认密码" style="width: 260px;" lay-verify="required|validateConfirmPassword" autocomplete="off" class="layui-input">
	      </div>
	    </div>
  </div>
   <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="updateUser">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<script type="text/javascript" th:inline="javascript">
layui.use(['form'], function(){
	 form = layui.form;
	 form.verify({
         validateOldPassword: function (value) {
        	 if([[${session.current_user.password}]]!=hex_md5(value)){
            	 return "原密码输入有误";
             }
         },
         validateConfirmPassword:function(value){
        	 if($("#password").val()!=value){
        		 return "新密码必须和确认密码相同";
        	 }
         }
     });
	 form.on('submit(updateUser)', function(data){
		  $.ajax({
              url: "/user/updateUserPassword",
              data: data.field,
              type: "post",
              success: function (result) {
            	if(result){
            		layMsg("修改成功",2000);
            		var index = parent.layer.getFrameIndex(window.name);
                	setTimeout(function(){parent.layer.close(index)}, 2000);
//                 	layui.alert("请重新登录");
//                 	window.location.href="exit";
            	}else{
            		layMsg("修改失败，请稍后重试",2000);
            	}
              },
              error: function (result) {
            	  layMsg("请求异常",2000);
              }
		});
	return false;	  
	});
});


</script>
</body>
</html>